Repository navigation
wireless/bluetooth/zblue: Run the work queues as pthreads - #4129
Open
chengkai15 wants to merge 1 commit into
Open
chengkai15 wants to merge 1 commit into
chengkai15 wants to merge 1 commit into
Conversation
In the flat build the Zephyr work queues are kernel threads, created with work_queue_create(), while the HCI receive thread and the threads of the application are pthreads of the application. The two kinds of thread are in different task groups and do not share per-process resources: - the thread-specific key of the porting layer is created in the group of the first thread that uses it. Since pthread_setspecific() rejects keys that were not created in the group of the caller, the other threads cannot record their k_thread, the cooperative lock is not released while the receive thread blocks in read(), and bt_enable() hangs: HCI_Reset is never sent. - the file descriptors: the HCI driver needed its own TX work queue, which opens the device again, to write from the host work queues. Create the work queues with work_queue_create_pthread(), so that all the threads of the host are pthreads of the application, and write the packets directly in send() again. The TX work queue and its thread are removed. Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Contributor
Author
|
This PR depends on apache/nuttx#22268 (
Please merge apache/nuttx#22268 first. The test results in the description are from master with both PRs applied. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
depends-on: apache/nuttx#22268
Summary
On current master,
zblue_peripheralon sim:zblue hangs inbt_enable(): HCI_Reset is never sent.In the flat build the Zephyr work queues are kernel threads (
work_queue_create()), while the HCI receive thread and the application threads are pthreads of the application. They are in different task groups:pthread_setspecific()rejects a key that was not created in the group of the caller, so it returnsEINVALin the receive thread. That thread then does not release the cooperative lock while it blocks inread(), and the host TX processor waits on that lock forever.This PR creates the work queues with
work_queue_create_pthread()(apache/nuttx#22268), so all host threads are pthreads of the application. The HCI driver writes insend()again, and the TX work queue and its thread are removed.uart_bth4writes each packet whole under its send lock, so writes from different threads do not interleave.Impact
zblue_hci_tx).Testing
sim:zblue on Linux with a CSR USB dongle (
CONFIG_SIM_HCISOCKET) as controller. BlueZgatttoolon a second CSR dongle is the central.master (nuttx c68c0bfbc1, nuttx-apps fa64592):
bt_enable()hangs, andpsshows the TX processor work queue waiting on a mutex held by the receive thread:With a debug print in
z_zblue_set_self(), the work queues (pid 0) set the key, and the receive thread of the application (pid 8) getsEINVAL:This PR + apache/nuttx#22268 on the same master:
All host threads now belong to the application (PID 8):
gatttool --char-read -a 0x000b), each on a new connection: 10/10 read4e 75 74 74 58 20 7a 62 6c 75 65("NuttX zblue").write failed.Not tested: protected and kernel builds (zblue supports only the simulator), real boards.